﻿/**
 *  @author alex
 */

Namespace("sketch.framework");

(function () {
    var fwk = sketch.framework;

    fwk.SelectFrame = klass(fwk.Rectangle, {
        __type__:"framework.SelectFrame",

        _constructor: function (onselect) {
            var startX, startY;
            var that = this;

            this.strokeStyle(fwk.Stroke.Black.cssColor);

            this.onselect = onselect;

            var setFrameBoundary = function (x, y, width, height) {
                that.left(x);
                that.top(y);
                that.width(width);
                that.height(height);
            };

            this.init = function(event) {
                startX = event.x;
                startY = event.y;
                setFrameBoundary(event.x, event.y, 0, 0);
                event.handled = true;
            };
            this.update = function(event) {
                setFrameBoundary(Math.min(startX, event.x), Math.min(startY, event.y),
                    Math.abs(startX - event.x), Math.abs(startY - event.y));
                event.handled = true;
            };
            this.complete = function(event){
                event.handled = true;
                this.onselect(this.getBoundaryRect());
            };
        },
        hitTest: function () {
            return true;
        },
        getSnapPoints: function () {
            return { xs: [], ys: [], center: {} };
        },
        canMultiSelect: function () {
            return false;
        }
    });
})();